import Vue from 'vue'
import App from './App.vue'
import router from './router'

import 'font-awesome/css/font-awesome.min.css'
import axios from 'axios'
import qs from 'qs'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import touch from 'vue-directive-touch'
import { VueJsonp } from 'vue-jsonp'

import {
    getCurDate,
    getSessionStorage,
    setSessionStorage,
    removeSessionStorage,
    getLocalStorage,
    setLocalStorage,
    removeLocalStorage
} from './common.js'


Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(touch);
Vue.use(VueJsonp);

//设置axios的基础url部分
// axios.defaults.baseURL = 'http://localhost:8080/elm/';
axios.defaults.baseURL = 'http://182.92.200.71:8080/elm/';
//将axios挂载到vue实例上，使用时就可以用this调用
Vue.prototype.$axios = axios;
// 第一步，在vue原型上定义一个自己的方法，一般叫$bus，为vue实例
Vue.prototype.$bus = new Vue();

Vue.prototype.$qs = qs;

Vue.prototype.$getCurDate = getCurDate;
Vue.prototype.$getSessionStorage = getSessionStorage;
Vue.prototype.$setSessionStorage = setSessionStorage;
Vue.prototype.$removeSessionStorage = removeSessionStorage;
Vue.prototype.$setLocalStorage = setLocalStorage;
Vue.prototype.$getLocalStorage = getLocalStorage;
Vue.prototype.$removeLocalStorage = removeLocalStorage;


router.beforeEach(function(to, from, next){
    let user = sessionStorage.getItem('user');
    //除了登录注册首页商家列表商家信息之外，都需要判断是否登录
    if (!(to.path == '/'||to.path == '/businessList'||to.path == '/businessInfo' || to.path == '/login' || to.path == '/register')) {
        if (user=null) {
            router.push('/login');
            location.reload();
        }
    }
    next();
})


// createApp(App).use(router).mount('#app')
new Vue({
    router,
    render: h => h(App)
}).$mount('#app')